<!-- 配送员选择弹窗 -->
<template>
  <el-dialog v-model="dialogVisible" title="分站选择" width="1000px" draggable align-center>
    <div class="main-box">
      <div class="table-box">
        <ProTable
          ref="proTable"
          title="供应商列表"
          highlight-current-row
          :columns="columns"
          :request-api="getVendorList"
          height="400px"
        >
          <!-- 表格操作 -->
          <template #operation="scope">
            <el-button type="primary" link :icon="Select" @click="selectVendor(scope.row)">选择</el-button>
          </template>
        </ProTable>
      </div>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import ProTable from "@/components/ProTable/index.vue";
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
import { Select } from "@element-plus/icons-vue";
import { Vendor } from "@/api/interface";
import { getVendorList } from "@/api/modules/vendor";

// 获取 ProTable 元素，调用其获取刷新数据方法（还能获取到当前查询参数，方便导出携带参数）
const proTable = ref<ProTableInstance>();

// 表格配置项
const columns: ColumnProps[] = [
  { prop: "vendorId", label: "id", width: 80, sortable: true, search: { el: "input" } },
  { prop: "vendorName", label: "供应商名称", width: 120, search: { el: "input" } },
  { prop: "vendorAddress.province", label: "省" },
  { prop: "vendorAddress.city", label: "市" },
  { prop: "vendorAddress.zone", label: "区" },
  { prop: "vendorAddress.detail", label: "详细地址" },
  { prop: "vendorContact", label: "联系人", search: { el: "input" } },
  { prop: "vendorPhone", label: "联系电话", search: { el: "input" } },
  { prop: "operation", label: "操作", width: 150, fixed: "right" }
];

onMounted(() => {});

const dialogVisible = ref(false);

// 接收父组件传过来的参数
const open = () => {
  dialogVisible.value = true;
};

// const handleSubmit = () => {};
const emit = defineEmits(["get-vendor"]);
const selectVendor = async (row: Vendor.ReqVendorList) => {
  emit("get-vendor", row);
  dialogVisible.value = false;
};

defineExpose({
  open
});
</script>
